include Makefile.Common

CXX= g++

PKG_CONFIG= `pkg-config --cflags glib-2.0` 

DESTDIR ?= /usr
prefix = $(DESTDIR)

RM= rm -f
CP= cp
MKDIR = mkdir -p

appdir= ${prefix}/share/applications/
sharedir= ${prefix}/share/picsimlab/
libdir= ${prefix}/lib/picsimlab/
execdir= ${prefix}/bin/

#lxrad automatic generated block start, don't edit below!

override CXXFLAGS+= -D_ARCH_=\"Linux64_WX\" -D_DATE_=\"${DATE}\"
override CXXFLAGS+= -D_VERSION_=\"$(VERSION)\" -Wall -g -O2 -flto=auto -D_SHARE_=\"../share/picsimlab/\" \
-D_LIB_=\"../lib/picsimlab/\" `lxrad-config --cxxflags`
override CXXFLAGS+= -DEXT_BROWSER
#override CXXFLAGS+=-fsanitize=address
#override CXXFLAGS+=-fno-omit-frame-pointer

LIBS =  `lxrad-config --libs` -lpicsim -lsimavr -lelf $(ELIBS) -lucsim -ldl -lgpsim
#LIBS=  ../../picsim/src/libpicsim_dbg.a ../../LXRAD_WX/libteste/liblxrad.a  ../../lunasvg/build/liblunasvg.a \
     ../../simavr/simavr/obj-x86_64-linux-gnu/libsimavr.a  -lopenal `wx-config --libs` `wx-config --libs stc` \
     -ldl -lgpsim

#lxrad automatic generated block end, don't edit above!

all: picsimlab
	
picsimlab: $(OBJS)
	@echo "Linking picsimlab"
	@$(CXX) $(CXXFLAGS) $(OBJS) -opicsimlab $(LIBS) 

%.o: %.cc
	@echo "Compiling $<"
	@$(CXX) -c $(CXXFLAGS) $< -o $@ 

install: all
	install -d $(execdir) $(sharedir) ${libdir} $(appdir) ${sharedir}/../icons/hicolor/64x64/apps/ \
	${sharedir}/../icons/hicolor/64x64/mimetypes/ ${sharedir}/../mime/application/
	$(CP) -dvf  ../share/picsimlab.desktop ${appdir} 
	$(CP) -drvf ../share/* ${sharedir}
	$(CP) -drvf ../lib/* ${libdir}
	$(CP) -dvf picsimlab ${execdir}
	strip ${execdir}picsimlab	
	xdg-icon-resource install --size 64  --novendor ../share/picsimlab.png 
	xdg-icon-resource install --context mimetypes --size 64 ../share/application-x-picsimlab-workspace.png application-x-picsimlab-workspace
	xdg-mime install --mode system ../share/application-x-picsimlab-workspace.xml
	xdg-mime default picsimlab.desktop application/x-picsimlab-workspace
	update-mime-database /usr/share/mime &
	update-desktop-database ${appdir} &

install_app: all
	install -d $(execdir) $(sharedir) ${libdir} $(appdir) ${sharedir}/../icons/hicolor/64x64/apps/ \
	${sharedir}/../icons/hicolor/64x64/mimetypes/ ${sharedir}/../mime/application/
	$(CP) -dvf  ../share/picsimlab.desktop ${appdir}/
	$(CP) -drvf ../share/* ${sharedir} 
	$(CP) -drvf ../lib/* ${libdir}
	$(CP) -dvf picsimlab ${execdir}
	$(CP) -drvf ../share/picsimlab.png ${sharedir}/../icons/hicolor/64x64/apps/
	$(CP) -drvf ../share/application-x-picsimlab-workspace.png  ${sharedir}/../icons/hicolor/64x64/mimetypes/
	$(CP) -drvf ../share/application-x-picsimlab-workspace.xml ${sharedir}/../mime/application/x-picsimlab-workspace.xml

install_docs:
	$(CP) -drvf ../docs ${sharedir} 
		

uninstall:
	$(RM) -drvf ${sharedir} 
	$(RM) -drvf ${libdir} 
	$(RM) -dvf ${execdir}picsimlab
	$(RM) -dvf ${appdir}picsimlab.desktop
	xdg-icon-resource uninstall  --size 64 --novendor picsimlab
	xdg-icon-resource uninstall  --context mimetypes --size 64 application-x-picsimlab-workspace
	xdg-mime uninstall  --mode system ../share/application-x-picsimlab-workspace.xml

run: all
	./picsimlab

clean:
	$(RM) picsimlab *.o core */*.o 
